import Vue from 'vue';
import Router from 'vue-router';
const _import = require('./_import_' + process.env.NODE_ENV);
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading

/* layout */
import Layout from '../views/layout/Layout';

/* login */
const Login = _import('login/index');
const authRedirect = _import('login/authredirect');

/* 首页统计 */
const HomePage = _import('homepage/index');

/* 报表统计 */
const Report = _import('report/index');
const ArchivesStatic = _import('report/archivesstatic');
const EnterpriseStatic = _import('report/enterprisestatic');
const FakeArchivesStatic = _import('report/fakearchivesstatic');
const PageViewStatic = _import('report/pageviewstatic');
const DataStatic = _import('report/datastatic');

/* 账号权限 */
const User = _import('user/index');
const UserEdit = _import('user/userEdit');
const UserAdd = _import('user/userAdd');
const Role = _import('user/role');
const RoleEdit = _import('user/roleEdit');
const RoleAdd = _import('user/roleAdd');
const ChangeUserPassword = _import('user/changepwd');

/* 广告设置 */
const AdvertisementIndex = _import('advertisement/index');
const AdvertisementAdd = _import('advertisement/advertisementadd');
const AdvertisementEdit = _import('advertisement/advertisementedit');
const SelectedAdvertisement = _import('advertisement/selectedadvertisement');
const SelectedAdvertisementAdd = _import('advertisement/selectedadvertisementadd');
const SelectedAdvertisementEdit = _import('advertisement/selectedadvertisementedit');

/* 企业管理 */
const EnterpriseList = _import('enterprise/index');
const Qualifications = _import('enterprise/qualifications');
const EnterpriseAdd = _import('enterprise/enterpriseadd');
const EnterpriseEdit = _import('enterprise/enterpriseedit');
const EnterpriseView = _import('enterprise/enterpriseview');
const QualificationAdd = _import('enterprise/qualificationadd');
const QualificationEdit = _import('enterprise/qualificationedit');
const EnterpriseRecycle = _import('enterprise/enterpriserecycle');

/* 产品档案 */
const ArchiveList = _import('archive/index');
const Authentication = _import('archive/authentication');
const ArchiveView = _import('archive/archiveview');
const ArchiveRecycle = _import('archive/archiverecycle');
const AuthenticationAdd = _import('archive/authenticationadd');
const AuthenticationEdit = _import('archive/authenticationedit');

/* 日志管理 */
const SystemLog = _import('systemlog/index');

/* components */
// const componentsIndex = _import('components/index');
// const Tinymce = _import('components/tinymce');
// const Markdown = _import('components/markdown');
// const JsonEditor = _import('components/jsoneditor');
// const DndList = _import('components/dndlist');
// const AvatarUpload = _import('components/avatarUpload');
// const Dropzone = _import('components/dropzone');
// const Sticky = _import('components/sticky');
// const SplitPane = _import('components/splitpane');
// const CountTo = _import('components/countTo');
// const Mixin = _import('components/mixin');

/* charts */
// const chartIndex = _import('charts/index');
// const KeyboardChart = _import('charts/keyboard');
// const KeyboardChart2 = _import('charts/keyboard2');
// const LineMarker = _import('charts/line');
// const MixChart = _import('charts/mixchart');

/* error page */
const Err404 = _import('error/404');
const Err401 = _import('error/401');

/* error log */
// const ErrorLog = _import('errlog/index');

/* excel */
// const ExcelDownload = _import('excel/index');

/* theme  */
// const Theme = _import('theme/index');

/* example*/
// const TableLayout = _import('example/table/index');
// const DynamicTable = _import('example/table/dynamictable');
// const Table = _import('example/table/table');
// const DragTable = _import('example/table/dragTable');
// const InlineEditTable = _import('example/table/inlineEditTable');

// const Form = _import('example/form');
// const Tab = _import('example/tab/index');

/* permission */
// const Permission = _import('permission/index');

Vue.use(Router);

 /**
  * icon : the icon show in the sidebar
  * hidden : if hidden:true will not show in the sidebar
  * redirect : if redirect:noredirect will not redirct in the levelbar
  * noDropdown : if noDropdown:true will not has submenu
  * meta : { role: ['admin'] }  will control the page role
  **/

export const constantRouterMap = [
    { path: '/login', component: Login, hidden: true },
    { path: '/authredirect', component: authRedirect, hidden: true },
    { path: '/404', component: Err404, hidden: true },
    { path: '/401', component: Err401, hidden: true }, {
      path: '/',
      component: Layout,
      redirect: '/homepage',
      name: '首页',
      hidden: true,
      children: [{ path: 'homepage', component: HomePage }]
    }, {
      path: '/personalcenter',
      component: Layout,
      redirect: 'noredirect',
      noDropdown: true,
      icon: 'gerenzhongxin',
      children: [
        { path: 'index', component: ChangeUserPassword, name: '个人中心', hidden: true }
      ]
    }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});

export const asyncRouterMap = [
  {
    path: '/report',
    component: Layout,
    redirect: 'noredirect',
    noDropdown: true,
    meta: { permissid: 'STATIC_REPORT' },
    icon: 'baobiao1',
    children: [{ path: 'index', component: Report, name: '报表统计', meta: { permissid: 'STATIC_REPORT' } },
    { path: 'pageviewstatic', component: PageViewStatic, name: '浏览量统计', meta: { permissid: 'STATIC_REPORT' } },
    { path: 'fakearchivesstatic', component: FakeArchivesStatic, name: '新增防伪档案统计', meta: { permissid: 'STATIC_REPORT' } },
    { path: 'enterprisestatic', component: EnterpriseStatic, name: '企业入驻统计', meta: { permissid: 'STATIC_REPORT' } },
    { path: 'archivesstatic', component: ArchivesStatic, name: '新建档案统计', meta: { permissid: 'STATIC_REPORT' } },
    { path: 'datastatic', component: DataStatic, name: '数据报表', meta: { permissid: 'STATIC_REPORT' } }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    name: '账号权限',
    meta: { permissid: 'ACCOUNT_AUTHORITY' },
    icon: 'zhquanxian1',
    children: [
      { path: 'index', component: User, name: '账号管理', meta: { permissid: 'ACCOUNT_MANAGE' }, icon: 'zhanghao' },
      { path: 'useredit', component: UserEdit, name: '编辑账号', hidden: true, meta: { permissid: 'ACCOUNT_MANAGE_UPDATE' } },
      { path: 'useradd', component: UserAdd, name: '新增账号', hidden: true, meta: { permissid: 'ACCOUNT_MANAGE_INSERT' } },
      { path: 'role', component: Role, name: '权限配置', meta: { permissid: 'AUTHORITY_CONFIG' }, icon: 'jiaose' },
      { path: 'roleedit', component: RoleEdit, name: '编辑角色', hidden: true, meta: { permissid: 'AUTHORITY_CONFIG_UPDATE' } },
      { path: 'roleadd', component: RoleAdd, name: '新增角色', hidden: true, meta: { permissid: 'AUTHORITY_CONFIG_INSERT' } },
      { path: 'changepwd', component: ChangeUserPassword, name: '用户密码修改', hidden: true }
    ]
  },
  {
    path: '/advertisement',
    component: Layout,
    redirect: 'noredirect',
    name: '广告设置',
    meta: { permissid: 'ADVERT_SET' },
    icon: 'guanggao1',
    children: [
      { path: 'index', component: AdvertisementIndex, name: '首页广告', meta: { permissid: 'HOMEPAGE_ADVERT' }, icon: 'guanggao3' },
      { path: 'selectedadvertisement', component: SelectedAdvertisement, name: '精选广告', meta: { permissid: 'SELPAGE_ADVERT' }, icon: 'chanpin1' },
      { path: 'advertisementadd', component: AdvertisementAdd, name: '新建首页广告', hidden: true, meta: { permissid: 'HOMEPAGE_ADVERT_INSERT' } },
      { path: 'advertisementedit', component: AdvertisementEdit, name: '编辑首页广告', hidden: true, meta: { permissid: 'HOMEPAGE_ADVERT_UPDATE' } },
      { path: 'selectedadvertisementedit', component: SelectedAdvertisementEdit, name: '编辑精选广告', hidden: true, meta: { permissid: 'SELPAGE_ADVERT_UPDATE' } },
      { path: 'selectedadvertisementadd', component: SelectedAdvertisementAdd, name: '新增精选广告', hidden: true, meta: { permissid: 'SELPAGE_ADVERT_INSERT' } }
    ]
  },
  {
    path: '/enterprise',
    component: Layout,
    redirect: 'noredirect',
    name: '企业管理',
    meta: { permissid: 'ENTERPRISE_MANAGE' },
    icon: 'qiye',
    children: [
      { path: 'index', component: EnterpriseList, name: '企业列表', meta: { permissid: 'ENTERPRISE_LIST' }, icon: 'qiye1' },
      { path: 'qualifications', component: Qualifications, name: '企业资质', meta: { permissid: 'ENTERPRISE_APTITUDE' }, icon: 'zhengshu1' },
      { path: 'enterpriseadd', component: EnterpriseAdd, name: '新建企业', hidden: true, meta: { permissid: 'ENTERPRISE_LIST_UPDATE777' } },
      { path: 'enterpriseedit', component: EnterpriseEdit, name: '编辑企业', hidden: true, meta: { permissid: 'ENTERPRISE_LIST_UPDATE' } },
      { path: 'enterpriseview', component: EnterpriseView, name: '查看企业', hidden: true, meta: { permissid: 'ENTERPRISE_LIST_VIEW' } },
      { path: 'qulificationedit', component: QualificationEdit, name: '编辑资质', hidden: true, meta: { permissid: 'ENTERPRISE_APTITUDE_UPDATE' } },
      { path: 'qulificationadd', component: QualificationAdd, name: '新增资质', hidden: true, meta: { permissid: 'ENTERPRISE_APTITUDE_INSERT' } },
      { path: 'enterpriserecycle', component: EnterpriseRecycle, name: '企业回收站', hidden: true, meta: { permissid: 'ENTERPRISE_LIST_RECYCLE' } }
    ]
  },
  {
    path: '/archive',
    component: Layout,
    redirect: 'noredirect',
    name: '档案管理',
    meta: { permissid: 'ARCHIVES_MANAGE' },
    icon: 'chanpin2',
    children: [
      { path: 'index', component: ArchiveList, name: '档案列表', meta: { permissid: 'ARCHIVES_LIST' }, icon: 'chanpin3' },
      { path: 'authentication', component: Authentication, name: '产品证书', meta: { permissid: 'PRODUCT_CERTIFI' }, icon: 'zhengshu2' },
      { path: 'archiveview', component: ArchiveView, name: '查看产品档案', hidden: true, meta: { permissid: 'ARCHIVES_LIST_VIEW' } },
      { path: 'archiverecycle', component: ArchiveRecycle, name: '档案回收站', hidden: true, meta: { permissid: 'ARCHIVES_LIST_RECYCLE' } },
      { path: 'authenticationedit', component: AuthenticationEdit, name: '编辑证书', hidden: true, meta: { permissid: 'PRODUCT_CERTIFI_UPDATE' } },
      { path: 'authenticationadd', component: AuthenticationAdd, name: '新增证书', hidden: true, meta: { permissid: 'PRODUCT_CERTIFI_INSERT' } }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: 'noredirect',
    noDropdown: true,
    meta: { permissid: 'LOGGER_MANAGER' },
    icon: 'rizhi1',
    children: [{ path: 'index', component: SystemLog, name: '日志管理', meta: { permissid: 'LOGGER_MANAGER' } }]
  }
];
